home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
writescr.c
< prev
next >
Wrap
Text File
|
1992-04-17
|
36KB
|
1,469 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#pragma segment 3270seg1
extern RGBColor realblack;
extern RGBColor realwhite;
void invldscr(cnr *cp)
{
GrafPtr gp;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (cp->myWindow == 0) return;
cp->needwrite = 1;
GetPort(&gp);
SetPort(cp->myWindow);
InvalRect(&(cp->textRect));
SetPort(gp);
checkpos(cp);
}
void checkpos(cnr *cp)
{
if (cp->myWindow == 0) return;
if (!(cp->cs.curpos)) return;
cp->statcpos = 1;
newstat(cp);
cp->statcpos = 0;
}
void writescr(char printflag, cnr *cp)
{
register unsigned short a, i, cattr, fattr, start, count;
unsigned short offset, lastfield;
char geflg, g;
static unsigned long * Ticks = (unsigned long *)0x16a;
unsigned long stasklim;
if (cp->myWindow == 0) return;
/* get field attribute for first screen position, even if it */
/* is defined by a subsequent field wrapping to the start. */
fattr = lastfield = 0;
if (cp->fmtscrn) {
if ((cp->atrbuff)[0] & 0x8000) {
lastfield = (cp->atrbuff)[0] & 0x3fdf;
fattr = lastfield & 0x3f1f;
}
else for (i = cp->maxoff; i > 0; i--)
if ((cp->atrbuff)[i] & 0x8000) {
lastfield = (cp->atrbuff)[i] & 0x3fdf;
fattr = lastfield & 0x3f1f;
break;
}
}
cp->WriteCurr = 0;
if (printflag == 0) EraseRect(&(cp->textRect));
cp->framedfield = 0;
cattr = fattr;
if (cp->tcpflg) stasklim = (*Ticks) + 4;
for (start = 0; start < cp->maxcnt; start += cp->scrhsize) {
if (cp->tcpflg) {
if ((*Ticks) > stasklim) {
myStask();
stasklim = (*Ticks) + 4;
}
}
count = 0;
geflg = 0;
offset = start;
MoveTo(cp->htxtstrt, cp->WriteCurr*cp->vtxtsize + cp->vtxtstrt);
for (i=0; i < cp->scrhsize; i++) {
a = (cp->atrbuff)[start+i];
g = (a & 0x40c0) != 0;
a &= 0xbfff;
if (a & 0x8000) {
dfield(offset, count, lastfield, cattr, geflg, cp);
/* attribute byte is a field by itself */
offset = start + i;
count = -1; /* indicates attribute byte */
fattr = a & 0x3fff;
dfield(offset, count, fattr, fattr, 0, cp);
lastfield = fattr & 0x3fdf; /* selection doesn't propagate */
fattr = lastfield & 0x3f1f;
cattr = fattr;
count = 0;
geflg = 0;
offset = start + i + 1;
}
else {
a &= 0x3f3f;
if ((a == 0) && (cattr == fattr)) {
count++;
geflg |= g;
continue;
}
if (a == cattr) {
count++;
geflg |= g;
continue;
}
/* else start new field */
dfield(offset, count, lastfield, cattr, geflg, cp);
count = 1;
offset = start + i;
cattr = a;
geflg = g;
}
}
dfield(offset, count, lastfield, cattr, geflg, cp);
cp->WriteCurr ++;
}
if (printflag) return;
cp->x = cp->curadr%cp->scrhsize;
cp->y = cp->curadr/cp->scrhsize;
defcursor(cp->x, cp->y, cp); /* define er rectangle for cursor */
if (!(cp->textmap)) drawcurs(0, cp);
}
void newcur(cnr *cp)
{
GrafPtr gp;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (cp->myWindow == 0) return;
GetPort(&gp);
SetPort(cp->myWindow);
if (cp->textmap) InvalRect(&(cp->er));
else drawcurs(1, cp);
cp->x = cp->curadr%cp->scrhsize;
cp->y = cp->curadr/cp->scrhsize;
defcursor(cp->x, cp->y, cp); /* define er rectangle for cursor */
if (cp->textmap) InvalRect(&(cp->er));
else drawcurs(0, cp);
SetPort(gp);
checkpos(cp);
}
void newchar(short offset, unsigned char value,
short atr, short fattr, cnr *cp)
{
short newatr, selattr;
(cp->chrbuff)[offset] = value;
if (cp->cutflag) { /* allow deletion of selection attribute */
(cp->atrbuff)[offset] = atr;
}
else { /* preserve selection attribute */
selattr = (cp->atrbuff)[offset] & 0x0020;
(cp->atrbuff)[offset] = (atr & 0xffdf) | selattr;
}
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (cp->myWindow == 0) return;
newatr = fattr & 0x3fff;
/* if (atr & 0x4000) newatr |= 0x4000; */
if (cp->in_len == 0) {
cp->in_len = 1;
cp->in_off = offset;
cp->in_atr = newatr;
return;
}
if ( (cp->in_atr != newatr) || (cp->in_off/cp->scrhsize != offset/cp->scrhsize) ||
(offset-cp->in_off-cp->in_len > 0) || (cp->in_off-offset > 1) ) {
dchar(cp->in_off, cp->in_len, cp->in_atr, cp);
cp->in_len = 1;
cp->in_off = offset;
cp->in_atr = newatr;
return;
}
if ((cp->in_off+cp->in_len) == offset) {
cp->in_len++;
return;
}
if (cp->in_off-offset == 1) {
cp->in_len++;
cp->in_off--;
}
}
void dchar(short offset, short len, short fattr, cnr *cp)
{
short i, selattr, dstart, dlen;
if (len < 1) return;
if (len == 1) {
seldchar(offset, len, (cp->atrbuff)[offset] & 0x3f3f, fattr, cp);
return;
}
selattr = (cp->atrbuff)[offset] & 0x3f3f;
dstart = offset;
dlen = 1;
for (i=1; i < len; i++)
if (((cp->atrbuff)[offset+i] & 0x3f3f) != selattr) {
seldchar(dstart, dlen, selattr, fattr, cp);
selattr = (cp->atrbuff)[offset+i] & 0x3f3f;
dstart = offset+i;
dlen = 1;
}
else dlen++;
seldchar(dstart, dlen, selattr, fattr, cp);
}
void seldchar(short offset, short len, short selattr, short fattr, cnr *cp)
{
Rect r;
register short x, y;
GrafPtr gp;
unsigned char attrbits;
RGBColor rgbtemp;
short chrtop;
char prot, fieldfont;
prot = (fattr & 0x2000) != 0;
fieldfont = (fattr & 0x00c0) >> 6;
fattr &= 0xff3f;
getdspatr(&attrbits, 0L, &rgbtemp, selattr, fattr, cp);
GetPort(&gp);
SetPort(cp->WritePtr);
if (cp->textmap) setgdev(cp);
y = offset/cp->scrhsize;
x = offset%cp->scrhsize;
chrtop = r.top = y*cp->vtxtsize;
if (cp->htxtstrt == 0) r.top--; /* adjust for 12-point */
r.left = cp->htxtstrt+x*cp->htxtsize;
r.bottom = r.top+cp->vtxtsize;
r.right = r.left + len * cp->htxtsize;
if (!(cp->textmap))
if ((cp->curadr >= offset) && (cp->curadr < offset+len)) drawcurs(1, cp);
if (cp->framedfield) { /* adjust to not erase any frames on screen */
r.bottom--;
}
if (colormac && (!cp->cs.nocolor))
if (attrbits & 0x20) { /* reversed field */
RGBBackColor(&rgbtemp);
if (cp->cs.invertbw) GetEntryColor(cp->myPalette, RGBwhite, &rgbtemp);
else GetEntryColor(cp->myPalette, RGBblack, &rgbtemp);
RGBForeColor(&rgbtemp);
}
else RGBForeColor(&rgbtemp); /* normal field */
EraseRect(&r);
if (!(attrbits & 0x80)) { /* displayable */
MoveTo(r.left, cp->vtxtstrt+chrtop);
txtfield(offset, len, attrbits, prot, fieldfont, cp);
/* if (fattr & 0x4000) fnum = APLFONT;
else fnum = cp->stdfont;
if (attrbits & 0x08) fnum += 2;
if (fnum != cp->stdfont) TextFont(fnum);
myDrawText(cp->chrbuff, offset, len, fnum, prot, cp);
if (fnum != cp->stdfont) TextFont(cp->stdfont); */
if (attrbits & 0x10) {
MoveTo(r.left, chrtop+cp->vtxtstrt+(cp->curvsize>>2)-3);
LineTo(r.right+1, chrtop+cp->vtxtstrt+(cp->curvsize>>2)-3);
}
if (((!colormac) || (cp->cs.nocolor)) && (attrbits & 0x20)) InvertRect(&r);
}
if (colormac && (!cp->cs.nocolor) && (attrbits & 0x20)) {
GetEntryColor(cp->myPalette, RGBback, &rgbtemp);
RGBBackColor(&rgbtemp);
}
SetPort(cp->myWindow);
if (cp->textmap) {
resetgdev();
if (r.top < cp->inrect.top) cp->inrect.top = r.top;
if (r.left < cp->inrect.left) cp->inrect.left = r.left;
if (r.bottom > cp->inrect.bottom) cp->inrect.bottom = r.bottom;
if (r.right > cp->inrect.right) cp->inrect.right = r.right;
}
else if ((cp->curadr >= offset) && (cp->curadr < offset+len)) drawcurs(0, cp);
SetPort(gp);
}
void newwrite(cnr *cp)
{
GrafPtr gp;
if (sw_bgrnd) return;
if (cp->myWindow == 0) return;
if (cp->in_len > 0) {
dchar(cp->in_off, cp->in_len, cp->in_atr, cp);
cp->in_len = 0;
}
if (!(cp->textmap)) return;
GetPort(&gp);
SetPort(cp->myWindow);
if (cp->inrect.top <= cp->inrect.bottom) {
InvalRect(&(cp->inrect));
}
cp->inrect.top = cp->inrect.left = 32767;
cp->inrect.bottom = cp->inrect.right = -32767;
SetPort(gp);
}
void dfield(short offset, short count, short fattr, short cattr,
char g, cnr *cp)
{
struct Rect z;
unsigned char attrbits, trim;
short xend, yend, txtcount, txtoff, adjcount, adjoff;
RGBColor rgbfield, rgbrev;
char prot, fieldfont;
short fnum;
if (count == 0) return;
fieldfont = (fattr & 0x00c0) >> 6;
fattr &= 0xff3f;
/* get attribute definition for this field */
prot = (fattr & 0x2000) != 0;
trim = 1;
getdspatr(&attrbits, &trim, &rgbfield, cattr, fattr, cp);
if (count == -1) {
attrbits = cp->cs.attrmap[6];
trim = 0;
count = 1;
if (cattr & 0x0020) {
attrbits &= 0x8f;
attrbits |= 0x20;
}
}
/* remember where to end up when done */
xend = cp->htxtstrt + (offset%cp->scrhsize)*cp->htxtsize + count*cp->htxtsize;
yend = cp->WriteCurr*cp->vtxtsize + cp->vtxtstrt;
/* if appropriate, calculate new count and offset to eliminate leading
and trailing blanks and nulls */
adjcount = txtcount = count;
adjoff = txtoff = offset;
calctrim(&txtoff, &txtcount, cp); /* don't draw blanks and nulls */
if (!(fattr & 0x2000)) trim = 0; /* unprotected not trimmed */
if (trim) {
adjcount = txtcount;
adjoff = txtoff;
}
/* define nominal rectangle for this update */
z.top = cp->WriteCurr * cp->vtxtsize;
z.bottom = z.top + cp->vtxtsize;
if (cp->htxtstrt == 0) { /* adjust for 12-point */
z.top--;
z.bottom--;
}
z.left = cp->htxtstrt + (adjoff%cp->scrhsize) * cp->htxtsize;
z.right = z.left + adjcount * cp->htxtsize;
/* define colors for normal or reversed field */
if (colormac && (!cp->cs.nocolor))
if (attrbits & 0x20) {
RGBBackColor(&rgbfield);
if (adjcount > 0) {
if (attrbits & 0x40) {
z.left -= 1;
z.right += 1 - cp->htxtstrt;
}
EraseRect(&z);
if (attrbits & 0x40) {
z.left += 1;
z.right -= 1 - cp->htxtstrt;
}
}
GetEntryColor(cp->myPalette, RGBback, &rgbrev);
RGBBackColor(&rgbrev);
if (cp->cs.invertbw) GetEntryColor(cp->myPalette, RGBwhite, &rgbrev);
else GetEntryColor(cp->myPalette, RGBblack, &rgbrev);
RGBForeColor(&rgbrev);
}
else RGBForeColor(&rgbfield);
/* draw text if not non-display or all blanks or nulls */
if (txtoff != offset) MoveTo(cp->htxtstrt+(txtoff%cp->scrhsize)*cp->htxtsize, yend);
if (!((attrbits & 0x80) || (txtcount == 0)))
if (g) {
txtfield(txtoff, txtcount, attrbits, prot, fieldfont, cp);
}
else {
if (fieldfont == 1) fnum = APLFONT;
else fnum = cp->stdfont;
if (attrbits & 0x08) fnum += 2;
if (fnum != cp->stdfont) TextFont(fnum);
myDrawText(cp->chrbuff, txtoff, txtcount, fnum, prot, cp);
if (fnum != cp->stdfont) TextFont(cp->stdfont);
}
MoveTo(xend, yend);
/* return if no other attributes */
if (!(attrbits & 0x70)) return;
/* return if trimming has removed field */
if (adjcount == 0) return;
/* frame if requested */
if (attrbits & 0x40) {
z.top -= 1;
z.left -= 2;
z.right += 2 - cp->htxtstrt;
if (colormac && (!cp->cs.nocolor)) RGBForeColor(&rgbfield);
FrameRect(&z);
z.top += 1;
z.bottom -= 1;
z.left += 1;
z.right -= 1;
cp->framedfield = 1;
}
/* underline if requested */
if (attrbits & 0x10) {
if (colormac && (!cp->cs.nocolor))
if (attrbits & 0x20) RGBForeColor(&rgbrev);
else RGBForeColor(&rgbfield);
MoveTo(z.left, yend+(cp->curvsize>>2)-3);
LineTo(z.right-1, yend+(cp->curvsize>>2)-3);
}
/* reverse if requested */
if (((!colormac) || (cp->cs.nocolor)) && (attrbits & 0x20)) InvertRect(&z);
/* leave pen ready for next character */
MoveTo(xend, yend);
}
void calctrim(short *offset, short *count, cnr *cp)
{
register short adjoff, adjcount, i, j, k;
adjcount = j = (*count);
adjoff = k = (*offset);
for (i = 0; i < j; i++) {
if (((cp->chrbuff)[k] == 0x40) || ((cp->chrbuff)[k] == 0x00)) {
adjoff++;
adjcount--;
}
else break;
k++;
}
j = adjcount;
k = adjoff + adjcount - 1;
for (i = 0; i < j; i++) {
if (((cp->chrbuff)[k] == 0x40) || ((cp->chrbuff)[k] == 0x00)) adjcount--;
else break;
k--;
}
(*offset) = adjoff;
(*count) = adjcount;
}
void getdspatr(unsigned char *atr_result,
unsigned char *trim_result,
RGBColor *color_result,
register unsigned short cattr,
register unsigned short fattr,
cnr *cp)
{
register unsigned char attrbits;
unsigned char exthi, color, trim, cnum;
static RGBColor * HiliteRGB = (RGBColor *)0xda0;
if (trim_result != 0) trim = (*trim_result);
/* determine extended highlighting value to use */
exthi = (cattr & 0x0018) >> 3;
if (exthi == 0) exthi = (fattr & 0x0018) >> 3;
/* get default, highlight, or non-display attribute */
switch ((fattr & 0x0C00) >> 10) {
case 0:
case 1: attrbits = cp->cs.attrmap[0];
break;
case 2: attrbits = cp->cs.attrmap[1];
break;
case 3: attrbits = cp->cs.attrmap[2];
exthi = 0; /* non-display cancels ext. high */
trim = 0;
break;
default: attrbits = 0;
break;
}
/* add extended highlighting to basic attributes */
switch (exthi) {
case 0: break;
case 1: attrbits |= cp->cs.attrmap[4];
break;
case 2: attrbits |= cp->cs.attrmap[3];
trim = 0;
break;
case 3: attrbits |= cp->cs.attrmap[5];
trim = 0;
break;
default: break;
}
/* adjust attrbits for mouse selection field */
if (cattr & 0x0020) {
attrbits &= 0x8f; /* cancel frame, reverse, underline */
attrbits |= 0x20; /* set reverse bit */
trim = 0; /* don't trim */
}
/* determine color value to use */
if (colormac && (!cp->cs.nocolor)) {
if (cattr & 0x0020) { /* use highlight color for selection text */
(*color_result) = (*HiliteRGB);
if ((((*color_result) == realblack) && (!(cp->cs.invertbw))) ||
(((*color_result) != realblack) && cp->cs.invertbw)) {
(*color_result).red = 0xffff - (*color_result).red;
(*color_result).green = 0xffff - (*color_result).green;
(*color_result).blue = 0xffff - (*color_result).blue;
}
}
else {
color = cattr & 0x0007;
if (color == 0) color = fattr & 0x0007;
if (color == 0) {
if (fattr & 0x2000) { /* protected */
if ((fattr & 0x0c00) == 0x0800) { /* high-intensity */
color = 7; /* white */
}
else {
if (cp->cs.basecolor || cp->colorfield) color = 4; /* green */
else color = 1; /* blue */
}
}
else { /* unprotected */
if ((fattr & 0x0c00) == 0x0800) { /* high-intensity */
if (cp->cs.basecolor || cp->colorfield) color = 7; /* white */
else color = 2; /* red */
}
else {
color = 4; /* green */
}
}
}
switch(color) {
case 1: cnum = RGBblue;
break;
case 2: cnum = RGBred;
break;
case 3: cnum = RGBpink;
break;
case 5: cnum = RGBturquoise;
break;
case 6: cnum = RGByellow;
break;
case 7: if (cp->cs.invertbw) cnum = RGBblack;
else cnum = RGBwhite;
break;
default: cnum = RGBgreen;
break;
}
GetEntryColor(cp->myPalette, cnum, color_result);
}
}
if (trim_result != 0) (*trim_result) = trim;
(*atr_result) = attrbits;
}
void txtfield(short offset, short count, unsigned char attrbits,
char prot, char fieldfont, cnr *cp)
{
register short start, len, lim, f, i, fnum;
register unsigned char font;
start = offset;
len = 0;
lim = offset + count;
if ((cp->atrbuff)[offset] & 0x4000) {
font = 1;
}
else {
font = ((cp->atrbuff)[offset] & 0x00c0) >> 6;
}
if (font == 0) font = fieldfont;
for (i=offset; i < lim; i++) {
if ((cp->atrbuff)[i] & 0x4000) {
f = 1;
}
else {
f = ((cp->atrbuff)[i] & 0x00c0) >> 6;
}
if (f == 0) f = fieldfont;
if (font == f) len++;
else {
if (font == 1) fnum = APLFONT;
else fnum = cp->stdfont;
if (attrbits & 0x08) fnum += 2;
TextFont(fnum);
myDrawText(cp->chrbuff, start, len, fnum, prot, cp);
font = f;
start = i;
len = 1;
}
}
if (font == 1) fnum = APLFONT;
else fnum = cp->stdfont;
if (attrbits & 0x08) fnum += 2;
TextFont(fnum);
myDrawText(cp->chrbuff, start, len, fnum, prot, cp);
if (fnum != cp->stdfont) TextFont(cp->stdfont);
}
void myDrawText(register unsigned char *textBuf,
register short firstByte,
register short byteCount,
short font, char prot, cnr *cp)
{
register short i, j;
if (byteCount <= 0) return;
if (cp->nl_handle == 0) { /* no translation */
if (((font == ALAFONT) || (font == BOLDALA)) && prot && (!(cp->plainala))) {
ALADrawText(textBuf, firstByte, byteCount);
}
else {
DrawText(textBuf, firstByte, byteCount);
}
return;
}
if ((font == cp->stdfont) || (font == (cp->stdfont+2))) {
j = firstByte;
for (i=0; i < byteCount; i++) {
(cp->nlbuff)[i] = (cp->nltab)[textBuf[j++]];
}
DrawText(cp->nlbuff, 0, byteCount);
}
else { /* translation does not apply to APL */
DrawText(textBuf, firstByte, byteCount);
}
}
void ALADrawText(unsigned char *textBuf,
short firstByte, short byteCount)
{
register unsigned char *sptr;
register short i, textlen, state;
unsigned char *textptr;
short blankcount;
sptr = textBuf+firstByte;
blankcount = textlen = 0;
textptr = sptr;
state = 0;
for (i=firstByte; i < firstByte+byteCount; i++) {
switch(alatype(sptr)) {
case 0: /* normal character */
switch (state) {
case 0: /* normal */
textlen++;
break;
case 1: /* last char. diacritic */
if (textlen > 1) {
DrawText(textptr, 0, textlen-1);
textptr += textlen-1;
}
drawdc(*textptr, *sptr);
movechr(-1);
blankcount++;
textptr = sptr;
textlen = 1;
state = 0;
break;
default:
break;
}
break;
case 1: /* blank */
switch (state) {
case 0: /* pending blanks */
if (blankcount == 0) {
textlen++;
}
else {
DrawText(textptr, 0, textlen);
blankcount++;
movechr(blankcount);
blankcount = 0;
textptr = sptr + 1;
textlen = 0;
state = 0;
}
break;
case 1: /* last char. diacritic */
if (textlen > 1) {
DrawText(textptr, 0, textlen-1);
textptr += textlen-1;
}
drawdc(*textptr, *sptr);
blankcount++;
textptr = sptr + 1;
textlen = 0;
state = 0;
break;
default:
break;
}
break;
case 2: /* diacritic */
switch (state) {
case 0: /* normal */
case 1: /* last char. diacritic */
textlen++;
state = 1;
break;
default:
break;
}
break;
default:
break;
}
sptr++;
}
if (textlen > 0) {
DrawText(textptr, 0, textlen);
}
if (blankcount > 0) {
movechr(blankcount);
}
}
short alatype(unsigned char *s)
{
register unsigned char c;
c = *s;
if ((c == 0x40) || (c == 0x00)) return(1); /* blank or null */
if ((c%16) < 10) return(0); /* normal character */
if (c < 0x80) return(0);
if ((c >= 0xa0) && (c <= 0xbf)) return(0);
if (c >= 0xf0) return(0);
return(2);
}
void movechr(short n)
{
FontInfo fi;
if (n == 0) return;
GetFontInfo(&fi);
Move(fi.widMax*n, 0);
}
void drawdc(register unsigned char dc,
register unsigned char c)
/* draw diacritic, adjusting postion depending on
the character being modified */
{
register char adjflag;
FontInfo fi;
adjflag = 0;
/* check for lowercase character */
if (c == 0x40) adjflag = 1;
else if ((c >= 0x52) && (c <= 0x58)) adjflag = 1;
else if ((c >= 0x81) && (c <= 0x85)) adjflag = 1;
else if ((c >= 0x87) && (c <= 0x88)) adjflag = 1;
else if ((c >= 0x94) && (c <= 0x99)) adjflag = 1;
else if (c == 0xa2) adjflag = 1;
else if ((c >= 0xa4) && (c <= 0xa9)) adjflag = 1;
if (adjflag) { /* check for upper diacritic */
if ((dc >= 0x8e) && (dc <= 0x8f)) adjflag = 0;
else if ((dc >= 0x9e) && (dc <= 0x9f)) adjflag = 0;
else if ((dc >= 0xca) && (dc <= 0xcc)) adjflag = 0;
else if (dc == 0xda) adjflag = 0;
else if ((dc >= 0xdc) && (dc <= 0xdd)) adjflag = 0;
else if (dc == 0xea) adjflag = 0;
else if (dc >= 0xec) adjflag = 0;
}
if (adjflag) {
GetFontInfo(&fi);
Move(0, fi.ascent/6); /* 1 for 9 pt., 2 for 12 pt. */
}
DrawChar(dc);
if (adjflag) Move(0, -(fi.ascent/6));
}
void statline(cnr *cp)
{
static unsigned char *days[] = {"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
};
static unsigned char *months[] = {"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
DateTimeRec today;
static unsigned long * Ticks = (unsigned long *)0x16a;
unsigned char errmsg[16];
char cpos;
char klock, kcode;
short vpos;
RGBColor rgbtemp;
if ((((*Ticks) - cp->last_t) > 540) || (cp->last_stat_time != cp->cs.stat_time)) {
if (cp->cs.stat_time >= 8) cp->cs.stat_time -= 8;
cp->last_stat_time = cp->cs.stat_time;
if (cp->cs.stat_time > 0) {
GetTime(&today);
if (cp->cs.stat_time == 1) {
if (today.hour == 0) today.hour = 12;
if (today.hour > 12) today.hour -= 12;
}
sprintf(cp->statresult,"%s %02d %s %02d:%02d",
days[today.dayOfWeek-1],today.day,months[today.month-1],
today.hour,today.minute);
}
else strcpy(cp->statresult, "");
}
if (colormac && (!cp->cs.nocolor) && cp->drawpict) {
GetEntryColor(cp->myPalette, RGBback, &rgbtemp);
RGBBackColor(&rgbtemp);
}
EraseRect(&(cp->statRect));
TextFont(SYMBOLFONT);
TextSize(12);
if (colormac && (!cp->cs.nocolor)) {
GetEntryColor(cp->myPalette, RGBstat, &rgbtemp);
RGBForeColor(&rgbtemp);
}
cpos = cp->cs.curpos;
klock = cp->kblock;
kcode = cp->kblcode;
vpos = cp->vpixsize - 12;
if (!klock) if (cp->wr_active) {
klock = 1;
kcode = 2;
}
if (cp->logon) {
MoveTo(-2, vpos);
DrawChar(0x00);
}
if (cp->online) {
MoveTo(7, vpos);
DrawChar(0x01);
}
MoveTo(16, vpos);
DrawChar(0x02);
if (cp->insmode) {
MoveTo(290, vpos);
DrawChar(0x07);
}
if (klock || (cp->vmxbgn && (!(cp->vmxsub)))) {
MoveTo(61, vpos);
DrawChar(0x03);
}
if (klock && (kcode == 2)) {
MoveTo(74, vpos);
DrawChar(0x08);
}
if (klock && (kcode == 3)) {
MoveTo(74, vpos);
DrawChar(0x09);
DrawChar(0x0a);
DrawChar(0x0b);
DrawChar(0x0c);
}
if ((!klock) && (cp->kb_err == 1)) {
MoveTo(74, vpos);
DrawChar(0x05);
}
if ((!klock) && (cp->kb_err == 2)) {
MoveTo(74, vpos);
DrawChar(0x04);
DrawChar(0x05);
DrawChar(0x06);
}
if (cp->ioerror != 0) {
MoveTo(150, vpos);
DrawChar(0x09);
DrawChar(0x0a);
DrawChar(0x0b);
DrawChar(0x0c);
MoveTo(175, vpos+1);
DrawChar(0x01);
}
if (cp->vmxbgn || ftpcopen || ftpdopen || ftplopen) {
cpos = 0;
MoveTo(315, vpos);
DrawChar(0x0e);
Move(-2, 0);
DrawChar(0x04);
DrawChar(0x06);
Move(-2, 0);
DrawChar(0x0e);
}
if (klock && (kcode == 4)) {
TextFont(0);
TextSize(0);
MoveTo(74, vpos+1);
DrawString("\pSession");
}
TextFont(1);
TextSize(0);
if (klock && (kcode == 1)) {
MoveTo(74, vpos+1);
DrawString("\pSYSTEM");
}
if (klock && (kcode == 3)) {
MoveTo(112, vpos+1);
DrawString("\p590");
}
if ((!klock) && (cp->kb_err == 1)) {
MoveTo(84, vpos);
DrawChar('>');
}
if ((!klock) && (cp->kb_err == 3)) {
MoveTo(74, vpos+1);
DrawString("\p?+");
}
if (cp->ioerror != 0) {
sprintf(errmsg,"%d",cp->ioerror);
MoveTo(188, vpos+1);
c2pstr(errmsg);
DrawString(errmsg);
p2cstr(errmsg);
}
if (cp->aplmode) {
MoveTo(245, vpos+1);
DrawString("\pAPL");
}
if (cpos) {
sprintf(errmsg,"%02d/%02d", cp->y+1, cp->x+1);
MoveTo(cp->cposRect.left, vpos+1);
c2pstr(errmsg);
DrawString(errmsg);
p2cstr(errmsg);
}
MoveTo(cp->hpixsize-134, vpos+1);
c2pstr(cp->statresult);
DrawString(cp->statresult);
p2cstr(cp->statresult);
MoveTo(-4,cp->vpixsize-25);
LineTo(cp->hpixsize-4,cp->vpixsize-25);
TextFont(cp->stdfont);
TextSize(cp->cur_ptsize);
if (colormac && (!cp->cs.nocolor) && cp->drawpict) {
if (cp->cs.invertbw) GetEntryColor(cp->myPalette, RGBwhite, &rgbtemp);
else GetEntryColor(cp->myPalette, RGBblack, &rgbtemp);
RGBBackColor(&rgbtemp);
}
}
void newstat(cnr *cp)
{
GrafPtr gp;
BitMap * srcbits;
if (sw_bgrnd) {
sw_upd = 1;
return;
}
if (cp->myWindow == 0) return;
if (!(cp->textmap)) { /* no screen buffer */
GetPort(&gp);
SetPort(cp->myWindow);
statline(cp);
/* ValidRect(&statRect); */ /* May need new grow icon */
SetPort(gp);
}
else { /* have screen buffer */
GetPort(&gp);
SetPort(cp->WritePtr);
setgdev(cp);
statline(cp);
resetgdev();
SetPort(cp->myWindow);
if (colormac && (!cp->cs.nocolor)) {
RGBForeColor(&realblack);
RGBBackColor(&realwhite);
srcbits = (BitMap *)(*(PixMapHandle)cp->WritePort.portBits.baseAddr);
}
else {
srcbits = &(cp->WritePort.portBits);
}
if (cp->statcpos) {
CopyBits(srcbits, &((cp->myWindow)->portBits),
&(cp->cposRect), &(cp->cposRect), srcCopy, 0L);
}
else {
CopyBits(srcbits, &((cp->myWindow)->portBits),
&(cp->statRect), &(cp->statRect), srcCopy, 0L);
}
/* ValidRect(&statRect); */ /* may need new grow icon */
SetPort(gp);
}
}
void beep(cnr *cp)
{
static short duration = 3;
static short sw_dur = 2;
OSErr rc;
if (cp != 0) {
if (cp->apiopen) {
if (cp->apihide) return;
}
}
if (sw_bgrnd) sw_beep = 1;
if (cp != 0) {
rc = mybeep(cp);
if (rc == 0) return;
}
if (sw_bgrnd || mf_bgrnd) {
SysBeep(sw_dur);
SysBeep(sw_dur);
}
else SysBeep(duration);
}
OSErr mybeep(cnr *cp)
{
OSErr rc, playrc;
SndChannelPtr default_scp;
SndCommand endcmd;
if (cp->sndhandle == 0) return(1);
if (sndactive) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
if (mf_bgrnd || sw_bgrnd) { /* play sound synchronously */
default_scp = 0;
rc = SndNewChannel(&default_scp, 0, 0L, 0L);
if (rc == noErr) {
playrc = SndPlay(default_scp, cp->sndhandle, 0);
rc = SndDisposeChannel(default_scp, 0);
if (playrc == noErr) return(rc);
else return(playrc);
}
else {
return(rc);
}
}
rc = SndNewChannel(&scp, 0, 0L, (SndCallBackProcPtr)sndproc);
if (rc != noErr) return(rc);
rc = SndPlay(scp, cp->sndhandle, true);
if (rc != noErr) {
SndDisposeChannel(scp, true);
return(rc);
}
sndactive = 1;
endcmd.cmd = callBackCmd;
endcmd.param1 = 0;
endcmd.param2 = GetA5();
rc = SndDoCommand(scp, &endcmd, true);
if (rc != noErr) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
return(rc);
}
void sndend(void)
{
if (sndactive == 1) sndactive = 2; /* indicate dispose call needed */
}
void drawcurs(char restore, cnr *cp) /* draw cursor in screen window */
{
RGBColor rgbchar, mywhite, myblack, myback;
unsigned short foffset, fattr, cattr;
unsigned char attrbits, trim;
short start, end, count, lend;
static unsigned char * hiliteMode = (unsigned char *)0x938;
/* invert rectangle if no color or unknown color */
if (((!colormac) || (cp->cs.nocolor)) || cp->drawpict) {
InvertRect(&(cp->er));
return;
}
/* get colors we will need */
GetEntryColor(cp->myPalette, RGBwhite, &mywhite);
GetEntryColor(cp->myPalette, RGBblack, &myblack);
GetEntryColor(cp->myPalette, RGBback, &myback);
if (!restore) { /* compute background if not restore call */
/* define attrbits and trim */
foffset = getattr(cp->curadr, cp);
fattr = (cp->atrbuff)[foffset];
cattr = (cp->atrbuff)[cp->curadr];
trim = 1;
getdspatr(&attrbits, &trim, &rgbchar, cattr, fattr, cp);
if (!(fattr & 0x2000)) trim = 0; /* unprotected not trimmed */
if (cattr & 0x8000) { /* handle attribute byte */
attrbits = cp->cs.attrmap[6];
trim = 0;
}
/* determine background color */
/* reversed or underline cursor & field */
if ((attrbits & 0x20) || ((attrbits & 0x10) && (!(cp->cs.blockcurs)))) {
if (trim) {
start = (cp->curadr/cp->scrhsize) * cp->scrhsize;
lend = start + cp->scrhoff;
if ((foffset >= start) && (foffset < cp->curadr))
start = foffset+1;
end = start;
while (end < lend) {
end++;
if ((cp->atrbuff)[end] & 0x8000) {
end--;
break;
}
}
count = end - start + 1;
calctrim(&start, &count, cp);
end = start + count - 1;
if ((count > 0) && (cp->curadr >= start) && (cp->curadr <= end)) trim = 0;
}
if (trim) cp->rgbbk = myback; /* trim actually applies where cursor is */
else if (((attrbits & 0x30) == 0x30) && (!(cp->cs.blockcurs))) {
/* reverse & underline & underline cursor */
if (cp->cs.invertbw) cp->rgbbk = mywhite;
else cp->rgbbk = myblack;
}
else cp->rgbbk = rgbchar; /* reverse | underline & underline cursor */
}
else cp->rgbbk = myback; /* normal */
}
/* hilight (or unhilight) cursor rectangle */
if (cp->cs.invertbw) {
HiliteColor(&myblack);
RGBBackColor(&(cp->rgbbk));
}
else {
RGBBackColor(&mywhite);
HiliteColor(&(cp->rgbbk));
}
(*hiliteMode) &= 0x7f;
InvertRect(&(cp->er));
/* restore what we changed */
HiliteColor(&realblack);
if (cp->textmap) RGBBackColor(&realwhite);
else RGBBackColor(&myback);
}
void defcursor(short cx, short cy, cnr *cp)
{
cp->er.left = cx * cp->htxtsize;
cp->er.top = cy * cp->vtxtsize;
cp->er.right = cp->er.left + cp->curhsize;
cp->er.bottom = cp->er.top + cp->curvsize;
if (cp->cs.blockcurs) return;
cp->er.bottom -= (cp->curvsize>>2) - 1;
cp->er.top = cp->er.bottom - 1;
}
void justGrowIcon(char rgnok, cnr *cp)
{
GrafPtr psave;
RGBColor myback, mystat, actback, actstat;
Rect temprect;
GetPort(&psave);
SetPort(cp->myWindow);
if (!rgnok) SetClip(cp->cliprgn);
if (colormac && (!cp->cs.nocolor)) {
GetEntryColor(cp->myPalette, RGBback, &myback);
GetEntryColor(cp->myPalette, RGBstat, &mystat);
actualcolor(&myback, &actback, cp);
actualcolor(&mystat, &actstat, cp);
if (actback == actstat) InvertColor(&mystat);
RGBForeColor(&mystat);
if (cp->textmap) RGBBackColor(&myback);
}
temprect = (cp->myWindow)->portRect;
temprect.top = temprect.bottom-15;
temprect.left = temprect.right-15;
EraseRect(&temprect);
MoveTo(temprect.left, temprect.bottom);
LineTo(temprect.left, temprect.top);
LineTo(temprect.right, temprect.top);
if (((WindowPeek)cp->myWindow)->hilited) {
temprect.left += 3;
temprect.right = temprect.left + 7;
temprect.top += 3;
temprect.bottom = temprect.top + 7;
FrameRect(&temprect);
MoveTo(temprect.right, temprect.bottom-5);
Line(3, 0);
Line(0, 8);
Line(-8, 0);
Line(0, -3);
}
if (colormac && (!cp->cs.nocolor) && cp->textmap) RGBBackColor(&realwhite);
if (!rgnok) SetClip(cp->destrgn);
SetPort(psave);
}
void xfGrowIcon(cnr *cp)
{
GrafPtr psave;
Rect temprect;
GetPort(&psave);
SetPort(cp->xdlgptr);
temprect = (cp->xdlgptr)->portRect;
temprect.top = temprect.bottom-15;
temprect.left = temprect.right-15;
EraseRect(&temprect);
MoveTo(temprect.left, temprect.bottom);
LineTo(temprect.left, temprect.top);
LineTo(temprect.right, temprect.top);
if (((WindowPeek)cp->xdlgptr)->hilited) {
temprect.left += 3;
temprect.right = temprect.left + 7;
temprect.top += 3;
temprect.bottom = temprect.top + 7;
FrameRect(&temprect);
MoveTo(temprect.right, temprect.bottom-5);
Line(3, 0);
Line(0, 8);
Line(-8, 0);
Line(0, -3);
}
SetPort(psave);
}
void InitClip(cnr *cp)
{
ClipRect(&((cp->myWindow)->portRect));
GetClip(cp->cliprgn);
cp->gr_rect = (cp->myWindow)->portRect;
cp->gr_rect.top = cp->gr_rect.bottom-15;
cp->gr_rect.left = cp->gr_rect.right-15;
RectRgn(temprgn, &(cp->gr_rect));
DiffRgn(cp->cliprgn, temprgn, cp->destrgn);
SetClip(cp->destrgn);
}
void mousesel(short function, short location, char doubleflag, cnr *cp)
{
short toploc, bottomloc;
short startcol, toprow, endcol, bottomrow, t;
short scrtop, scrbottom, scrtop2, scrbottom2;
short scrstart, scrend, scrleft, scrright;
switch(function) {
case 0: /* initialization */
cp->init_loc = location;
cp->showsel = 0;
break;
case 1: /* display call */
case 2:
if (location != cp->init_loc) {
if (cp->showsel) {
if (location == cp->sel_loc) break;
invsel(&(cp->lastsel), cp);
}
/* define lastsel */
toploc = cp->init_loc;
bottomloc = location;
if (toploc > bottomloc) {
toploc = location;
bottomloc = cp->init_loc;
}
if (function == 2) {
bottomloc--;
if (doubleflag) wordadj(&toploc, &bottomloc, 0, cp);
}
startcol = toploc % cp->scrhsize;
endcol = bottomloc % cp->scrhsize;
toprow = toploc / cp->scrhsize;
bottomrow = bottomloc / cp->scrhsize;
if ((function == 1) && (startcol > endcol)) {
t = startcol;
startcol = endcol;
endcol = t;
}
scrtop = toprow * cp->vtxtsize + cp->htxtstrt - 1;
scrbottom2 = bottomrow * cp->vtxtsize + cp->htxtstrt - 1;
scrtop2 = (toprow+1) * cp->vtxtsize + cp->htxtstrt -1;
scrbottom = (bottomrow+1) * cp->vtxtsize + cp->htxtstrt -1;
scrstart = startcol * cp->htxtsize;
scrleft = 0;
scrend = (endcol+1) * cp->htxtsize + 1;
scrright = cp->scrhsize * cp->htxtsize + 1;
if ((function == 1) ||
((startcol == 0) && (endcol == cp->scrhoff)) ||
(toprow == bottomrow)) {
cp->lastsel.x1 = cp->lastsel.x2 =
cp->lastsel.x3 = cp->lastsel.x8 = scrstart;
cp->lastsel.x4 = cp->lastsel.x5 =
cp->lastsel.x6 = cp->lastsel.x7 = scrend;
cp->lastsel.y1 = cp->lastsel.y2 =
cp->lastsel.y3 = cp->lastsel.y4 = scrtop;
cp->lastsel.y5 = cp->lastsel.y6 =
cp->lastsel.y7 = cp->lastsel.y8 = scrbottom;
}
else {
cp->lastsel.x1 = scrleft;
cp->lastsel.y1 = scrtop2;
cp->lastsel.x2 = scrstart;
cp->lastsel.y2 = scrtop2;
cp->lastsel.x3 = scrstart;
cp->lastsel.y3 = scrtop;
cp->lastsel.x4 = scrright;
cp->lastsel.y4 = scrtop;
cp->lastsel.x5 = scrright;
cp->lastsel.y5 = scrbottom2;
cp->lastsel.x6 = scrend;
cp->lastsel.y6 = scrbottom2;
cp->lastsel.x7 = scrend;
cp->lastsel.y7 = scrbottom;
cp->lastsel.x8 = scrleft;
cp->lastsel.y8 = scrbottom;
if (startcol == 0) {
cp->lastsel.x2 = cp->lastsel.x3 = cp->lastsel.x1;
cp->lastsel.y1 = cp->lastsel.y2 = cp->lastsel.y3;
}
if (endcol == cp->scrhoff) {
cp->lastsel.x6 = cp->lastsel.x7 = cp->lastsel.x5;
cp->lastsel.y5 = cp->lastsel.y6 = cp->lastsel.y7;
}
}
invsel(&(cp->lastsel), cp);
cp->showsel = 1;
cp->sel_loc = location;
break;
}
if (cp->showsel == 0) break;
invsel(&(cp->lastsel), cp);
cp->showsel = 0;
break;
case 3: /* termination */
if (cp->showsel == 0) break;
invsel(&(cp->lastsel), cp);
cp->showsel = 0;
break;
default:
break;
}
}
void invsel(selcoord *r, cnr *cp)
{
PenState ps;
GrafPtr gp;
static Pattern gray =
{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
selcoord s;
s = *r;
GetPort(&gp);
SetPort(cp->myWindow);
GetPenState(&ps);
PenPat(&gray);
PenMode(patXor);
MoveTo(s.x1, s.y1);
if ((s.x2 != s.x1) || (s.y2 != s.y1)) {
if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
LineTo(s.x6, s.y6);
MoveTo(s.x2, s.y2);
}
else LineTo(s.x2, s.y2);
}
if ((s.x3 != s.x2) || (s.y3 != s.y2)) LineTo(s.x3, s.y3);
LineTo(s.x4, s.y4);
LineTo(s.x5, s.y5);
if ((s.x6 != s.x5) || (s.y6 != s.y5)) {
if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
LineTo(s.x2, s.y2);
MoveTo(s.x6, s.y6);
}
else LineTo(s.x6, s.y6);
}
if ((s.x7 != s.x6) || (s.y7 != s.y6)) LineTo(s.x7, s.y7);
LineTo(s.x8, s.y8);
LineTo(s.x1, s.y1);
SetPenState(&ps);
SetPort(gp);
}